using Mogre;
using OpenViewer.Framework;
using OpenViewer.Models;
using ThirdLife.Render.MogrePlugin.Common;

namespace ThirdLife.Render.MogrePlugin
{
  public class EntityWrapper
  {
    public EntityObject Ent;
    public SceneNode Node;
    public PrimitiveBaseShape NewShape;
    private IPrimManager primManager;

    public EntityWrapper()
    {
    }

    public EntityWrapper(EntityObject ent, SceneNode node, IPrimManager parent)
    {
      Node = node;
      Ent = ent;
      primManager = parent;
      ent.OnChangePosition += SetPosition;
      ent.OnChangeScale += SetScale;
      ent.OnChangeShape += SetShape;
    }

    public void SetPosition(Math3D.Vector3 position)
    {
      if (Node != null)
      {
        Mogre.Vector3 pos = new Mogre.Vector3(position.x, position.y, position.z);
        Node.Position = pos;
      }
    }

    public void SetScale(Math3D.Vector3 scale)
    {
      if (Node != null)
      {
        //scale is in LL axis so convert, err no don't as we rotate the node instead
        //  Mogre.Vector3 sc = new Mogre.Vector3(scale.y, scale.z, scale.x);
        Mogre.Vector3 sc = new Mogre.Vector3(scale.y, scale.x, scale.z);
        Node.SetScale((sc));
      }
    }

    public void SetShape(PrimitiveBaseShape shape)
    {
      NewShape = shape;
      primManager.RequestPrimUpdate(this);
    }

  }
}